package api

import (
	"2301house/api/handler"
	"2301house/api/middleware"
	"2301house/consts"
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
)

func LoadRoutes(r *gin.Engine) {
	r.Use(middleware.Cors())
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register) //注册
			user.POST("/login", handler.Login)       //登录
			user.POST("/perfect", handler.PerToken)  //刷新token
		}

		house := api.Group("/house")
		{
			house.Use(gojwt.JWTAuth(consts.JWT_KEY))
			house.POST("/add", handler.AddHouse)                 //发布房源
			house.GET("/page", handler.PageHouse)                //房源列表接口（支持标题过滤 + 分页）
			house.GET("/detail", handler.Detail)                 //房源详情
			house.POST("/update", handler.UpdateHouseType)       //修改房源状态
			house.POST("/uploadImage", handler.UploadHouseUrl)   //上传房源图片
			house.POST("/uploadVideo", handler.UploadHouseVideo) //上传房源视频
			house.POST("/updatePrice", handler.UpdateHousePrice) // 修改价格
		}
		reservation := api.Group("/reservation")
		{
			reservation.Use(gojwt.JWTAuth(consts.JWT_KEY))
			reservation.POST("/add", handler.AddTime) //预约看房
			reservation.POST("/del", handler.DelTime) //取消看房
		}
		order := api.Group("/order")
		{
			order.Use(gojwt.JWTAuth(consts.JWT_KEY))
			order.POST("/add", handler.AddOrder)          //添加订单
			order.POST("/upload", handler.UploadPayUrl)   // 添加支付凭证
			order.POST("update", handler.UpdateOrderType) //修改订单状态

		}
		admin := api.Group("/admin")
		{
			admin.Use(gojwt.JWTAuth(consts.JWT_KEY))
			admin.POST("update", handler.AdminUpdateOrderType) //修改订单状态
			admin.GET("/list", handler.AdminOrderList)         //查看房源
		}

		chat := api.Group("/chat")
		{
			chat.Use(gojwt.JWTAuth(consts.JWT_KEY))
			chat.GET("/ws", handler.Chat)
		}

	}
}
